<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>富扬数据看板</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="/stylesheets/css/bootstrap.min.css">
  <link rel="stylesheet" href="/stylesheets/css/AdminLTE.min.css">
  <link rel="stylesheet" href="/stylesheets/skins/_all-skins.min.css">
  <style>
    .power-box-msg{
      position: absolute;
      left: 0; right: 0;
      width: 200px; margin: 0px auto;
      padding: 10px;
      background: rgba(230,230,230,0.6);
      text-align: center;
      border-radius: 6px;
      font-size: 16px;
    }
    .content-header>h1>.breadcrumb {
      background: transparent;
      margin-top: 0;
      margin-bottom: 0;
      font-size: 12px;
      padding: 7px 5px;
      border-radius: 2px;
      display: inline-block;
    }
  </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<!-- Site wrapper -->
<div class="wrapper">

  <%- include("./public/header.ejs") %>

  <%- include("./public/aside.ejs") %>

  <div class="content-wrapper">
    <section class="content-header">
      <h1>
        权限管理
        <ol class="breadcrumb">
          <li><a href="/"><i class="glyphicon glyphicon-dashboard"></i>首页</a></li>
          <li><a href="/user">人员管理</a></li>
          <li class="active">修改权限</li>
        </ol>
      </h1>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-md-12">
          <div class="box">
            <!-- 如果有消息，显示它 -->
            <% if (messages && messages.success) { %>
              <div class="power-box-msg" style="color:green;"> <%= messages.success %> </div>
            <% } %>
            <% if (messages && messages.error) { %>
              <div class="power-box-msg" style="color:red;"> <%= messages.error %> </div>
            <% } %>
            <form action="/user/power/set" method="post">
              <div class="box-header">
                正在修改：<b class="userName"></b> 的权限
                <input type="text" class="uId" name="uId" readonly style="visibility: hidden;" />
                <button class="btn btn-info btn-xs" type="submit" style="float: right;">提交</a>
              </div>
              <div class="box-body">
                <table class="table table-bordered table-condensed table-striped table-hover">
                  <thead>
                    <tr>
                      <th>类目</th>
                      <th>查看</th>
                      <th>添加</th>
                      <th>删除</th>
                      <th>修改</th>
                      <th>导出</th>
                      <th>导入</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td>订单管理</td>
                      <td>
                        <input type="checkbox" id="a" name="powerList" value="/order"><label for="a">查看订单</label><br>
                        <input type="checkbox" id="b" name="powerList" value="/order/search"><label for="b">搜索订单</label>
                      </td>
                      <td><input type="checkbox" id="c" name="powerList" value="/order/add"><label for="c">添加订单</label></td>
                      <td><input type="checkbox" id="d" name="powerList" value="/order/delete"><label for="d">删除订单</label></td>
                      <td>
                        <input type="checkbox" id="e" name="powerList" value="/order/setUser"><label for="e">修改订单责任人</label><br>
                        <input type="checkbox" id="e2" name="powerList" value="/order/set"><label for="e2">修改订单基本信息</label><br>
                        <input type="checkbox" id="f" name="powerList" value="/order/locking"><label for="f">锁定订单</label>
                      </td>
                      <td>
                        <input type="checkbox" id="g" name="powerList" value="/order/exportTemp"><label for="g">导出模板</label><br>
                        <input type="checkbox" id="h" name="powerList" value="/order/export"><label for="h">导出订单</label>
                      </td>
                      <td><input type="checkbox" id="i" name="powerList" value="/order/import"><label for="i">导入订单</label></td>
                    </tr>
                    <tr>
                      <td>用户管理</td>
                      <td><input type="checkbox" id="k" name="powerList" value="/user"><label for="k">查看用户</label></td>
                      <td><input type="checkbox" id="l" name="powerList" value="/user/add"><label for="l">添加用户</label></td>
                      <td><input type="checkbox" id="m" name="powerList" value="/user/deleteUser"><label for="m">删除用户</label></td>
                      <td>
                        <input type="checkbox" id="n" name="powerList" value="/user/set"><label for="n">修改用户部门&职务</label><br>
                        <input type="checkbox" id="o" name="powerList" value="/user/password"><label for="o">重置密码</label><br>
                        <input type="checkbox" id="p" name="powerList" value="/user/power"><label for="p">修改权限</label>
                      </td>
                      <td colspan="2"></td>
                    </tr>
                    <tr>
                      <td>客户管理</td>
                      <td><input type="checkbox" id="r" name="powerList" value="/customer"><label for="r">查看客户</label></td>
                      <td><input type="checkbox" id="s" name="powerList" value="/customer/add"><label for="s">添加客户</label></td>
                      <td><input type="checkbox" id="t" name="powerList" value="/customer/delete"><label for="t">删除客户</label></td>
                      <td><input type="checkbox" id="i1" name="powerList" value="/customer/set"><label for="i1">修改客户</label></td>
                      <td colspan="2"></td>
                    </tr>
                    <tr>
                      <td>部门管理</td>
                      <td><input type="checkbox" id="v" name="powerList" value="/setting"><label for="v">查看部门</label></td>
                      <td><input type="checkbox" id="w" name="powerList" value="/setting/addTeam"><label for="w">添加部门</label></td>
                      <td><input type="checkbox" id="x" name="powerList" value="/setting/deleteTeam"><label for="x">删除部门</label></td>
                      <td colspan="3"></td>
                    </tr>
                    <tr>
                      <td>职位管理</td>
                      <td><input type="checkbox" id="z" name="powerList" value="/setting"><label for="z">查看职位</label></td>
                      <td><input type="checkbox" id="a1" name="powerList" value="/setting/addJob"><label for="a1">添加职位</label></td>
                      <td><input type="checkbox" id="b1" name="powerList" value="/setting/deleteJob"><label for="b1">删除职位</label></td>
                      <td colspan="3"></td>
                    </tr>
                    <tr>
                      <td>汇率管理</td>
                      <td><input type="checkbox" id="d1" name="powerList" value="/setting"><label for="d1">查看汇率</label></td>
                      <td><input type="checkbox" id="e1" name="powerList" value="/setting/addExchangeRate"><label for="e1">添加汇率</label></td>
                      <td></td>
                      <td><input type="checkbox" id="f1" name="powerList" value="/setting/updateExchangeRate"><label for="f1">修改汇率</label></td>
                      <td colspan="2"></td>
                    </tr>
                    <tr>
                      <td>提成管理</td>
                      <td><input type="checkbox" id="g1" name="powerList" value="/commission"><label for="g1">查看提成</label></td>
                      <td><input type="checkbox" id="h1" name="powerList" value="/commission/exportTemp"><label for="h1">导出模板</label></td>
                      <td></td>
                      <td><input type="checkbox" id="i2" name="powerList" value="/commission/export"><label for="i2">导出提成</label></td>
                      <td><input type="checkbox" id="j1" name="powerList" value="/commission/import"><label for="j1">导入提成</label></td>
                      <td><input type="checkbox" id="k1" name="powerList" value="/commission/save"><label for="k1">保存提成</label></td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </form>
          </div>
        </div>
      </div>
    </section>
  </div>

  <%- include("./public/footer.ejs") %>
</div>

<script src="/javascripts/jquery.min.js"></script>
<script src="/javascripts/bootstrap.min.js"></script>
<script src="/javascripts/adminlte.min.js"></script>
<script>

  const userData = <%- JSON.stringify(userData) %>;

  $(".userName").html( userData.employeesName );

  $("input[type=checkbox]").each((idx,val)=>{
    val.checked = userData.power.includes( val.value );
  })

  $(".uId").val( location.search.split('=')[1] );
</script>
</body>
</html>
